package com.nst.saicsecu;

import com.thingworx.metadata.annotations.ThingworxBaseTemplateDefinition;
import com.thingworx.metadata.annotations.ThingworxServiceDefinition;
import com.thingworx.metadata.annotations.ThingworxServiceResult;
import com.thingworx.things.Thing;
import com.thingworx.webservices.context.ThreadLocalContext;

@ThingworxBaseTemplateDefinition(name = "GenericThing")
public class SAICCurrentSessionInfoTemplate extends Thing {
  private static final String IDM_USER_KEY = "idm_user_name";

  @ThingworxServiceDefinition(name = "GetCurrentUser", description = "get current login user")
  @ThingworxServiceResult(name = "result", description = "the login user name", baseType = "STRING")
  public String GetCurrentUser() {
    final Object loginUserName = ThreadLocalContext.getSession().getAttribute(IDM_USER_KEY);
    if (loginUserName == null) {
      return "";
    }
    return (String) loginUserName;
  }
}
